package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class GUIHomeIcon extends JPanel{
	private static final long serialVersionUID = 1L;
	public static final Color RED = new Color(230,92,92);
	public static final Color BLUE = new Color(110, 192, 210);
	public static final Color GREEN = new Color(125, 198, 146);
	public static final Color YELLOW = new Color(223, 187, 65);
	public static final Color BROWN = new Color(216, 142, 100);
	public static final Color PUZZLE = new Color(221, 107,174);
	
	private boolean isMovedOn;
	private boolean isClicked;
	private JLabel icon;
	private JLabel tittle;
	
	public GUIHomeIcon(int width, int height) {
		setOpaque(true);
		this.setPreferredSize(new Dimension(width, height));
		icon = new JLabel();
		icon.setIconTextGap(0);
		tittle = new JLabel();
		tittle.setFont(tittle.getFont().deriveFont(20f));
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JPanel zzz = new JPanel(new FlowLayout(FlowLayout.CENTER));
		zzz.setOpaque(false);
		zzz.add(icon);
		add(zzz);
		JPanel titlepanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		titlepanel.setOpaque(false);
		titlepanel.add(tittle);
		add(titlepanel);
	}
	
	public void setIcon(ImageIcon icon){
		this.icon.setIcon(icon);
	}
	
	public void setTitle(String tittle){
		this.tittle.setText(tittle);
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d;
		g2d = (Graphics2D) g;
		
		g2d.setRenderingHint(
			    RenderingHints.KEY_ANTIALIASING,
			    RenderingHints.VALUE_ANTIALIAS_ON);
		
		RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, this.getWidth()-1, this.getHeight()-1, 10, 10);
		
		g2d.setColor(new Color(245, 245, 245, 245));
		g2d.fill(roundedRectangle);
		
		g2d.setColor(new Color(100, 100, 100, 150));
		g2d.draw(roundedRectangle);
		//
		g2d.setColor(new Color(60,60,60,40));
		g2d.fillRect(0, this.getHeight()/4*3+10, this.getWidth(), this.getHeight() -this.getHeight()/4*3-10);
		
		if(isMovedOn){
			g2d.setColor(CustomJButton.DARKER);
			g2d.fill(roundedRectangle);
		}
		if(isClicked){
			g2d.setColor(CustomJButton.LIGHTER);
			g2d.fill(roundedRectangle);
		}
		g2d.setRenderingHint(
			    RenderingHints.KEY_ANTIALIASING,
			    RenderingHints.VALUE_ANTIALIAS_DEFAULT);
	}
	
	public boolean isMovedOn() {
		return isMovedOn;
	}

	public void setMovedOn(boolean isMovedOn) {
		this.isMovedOn = isMovedOn;
	}

	public boolean isClicked() {
		return isClicked;
	}

	public void setClicked(boolean isClicked) {
		this.isClicked = isClicked;
	}
}
